package com.yb0os1.controller.admin;

import com.yb0os1.dto.CategoryDTO;
import com.yb0os1.entity.Category;
import com.yb0os1.result.PageResult;
import com.yb0os1.result.Result;
import com.yb0os1.serve.CategoryServe;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("adminCategoryController")
@RequestMapping("/admin/category")
@Tag(name = "处理分类的各种操作")
public class CategoryController {
    @Autowired
    private CategoryServe categoryServe;
    @PostMapping
    @Operation(summary = "新增分类")
    public Result<String> addCategory(@RequestBody CategoryDTO categoryDTO){
        categoryServe.addCategory(categoryDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @Operation(summary = "分类分页查询")
    public Result<PageResult> pageSelect(String name,Integer page,Integer pageSize,Integer type){
        PageResult pageResultResult = categoryServe.pageSelect(name, page, pageSize, type);
        return Result.success(pageResultResult);
    }

    @PostMapping("/status/{status}")
    @Operation(summary = "启用或者禁用分类")
    public Result<String> isOpenCloseCategory(Long id, @PathVariable Integer status){
        categoryServe.isOpenCloseCategory(id,status);
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "修改套擦")
    public Result<String> updateCategory(@RequestBody CategoryDTO categoryDTO){
        categoryServe.updateCategory(categoryDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "根据类型查询分类")
    public Result<List<Category>> getCategoryByType(Integer type){
        return Result.success(categoryServe.getCategoryByType(type));
    }

    @DeleteMapping
    @Operation(summary = "删除套餐")
    public Result<String> deleteCategory(Long id){
        categoryServe.deleteCategory(id);
        return Result.success();
    }
}
